local extension = Package("sktiangang")
extension.extensionName = "jilvRem"

local U = require "packages/utility/utility"

Fk:loadTranslationTable{
  ["jilvRem"] = "极略三国",
  ["sktiangang"] = "极略三国-天罡",
  ["sk"] = "极略",

  ["SkSkills"] = "技能库",
}
Fk:addQmlMark{
  name = "SkSkills",
  qml_path = "packages/jilvRem/qml/SkSkills",
  how_to_show = function(name, value, p)
    if string.startsWith(name, "@[SkSkills]") and type(value) == "table" then
      return tostring(#value)
    end
    return ""
  end,
}

local kuaiyue = General(extension, "sk__kuaiyue", "qun", 3)
local sk__yidu = fk.CreateTriggerSkill{
  name = "sk__yidu",
  anim_type = "drawcard",
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and player.phase == Player.NotActive and player:usedSkillTimes(self.name, Player.HistoryTurn) == 0 and
      player.room.current and not player.room.current.dead and not player.room.current:isKongcheng() then
      for _, move in ipairs(data) do
        if move.from and move.from == player.id then
          for _, info in ipairs(move.moveInfo) do
            if info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip then
              if table.find(player.room.current:getCardIds("h"), function(id)
                return Fk:getCardById(id).suit == Fk:getCardById(info.cardId).suit and
                  Fk:getCardById(info.cardId).suit ~= Card.NoSuit
                end) then
                return true
              end
            end
          end
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local suits = {}
    for _, move in ipairs(data) do
      if move.from and move.from == player.id then
        for _, info in ipairs(move.moveInfo) do
          if info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip then
            if Fk:getCardById(info.cardId).suit ~= Card.NoSuit then
              table.insertIfNeed(suits, Fk:getCardById(info.cardId).suit)
            end
          end
        end
      end
    end
    local n = 0
    for _, id in ipairs(room.current:getCardIds("h")) do
      if table.contains(suits, Fk:getCardById(id).suit) then
        n = n + 1
      end
    end
    player:drawCards(n, self.name)
  end,
}
local sk__zhubao = fk.CreateTriggerSkill{
  name = "sk__zhubao",
  anim_type = "drawcard",
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and player.phase ~= Player.NotActive and not player:isKongcheng() then
      local tos = {}
      for _, move in ipairs(data) do
        if move.from and move.from ~= player.id and not table.contains(player:getTableMark("sk__zhubao-turn"), data.from) then
          local yes = false
          for _, info in ipairs(move.moveInfo) do
            if info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip then
              if table.find(player:getCardIds("h"), function(id)
                return Fk:getCardById(id).suit == Fk:getCardById(info.cardId).suit and
                  Fk:getCardById(info.cardId).suit ~= Card.NoSuit
                end) then
                yes = true
              end
            end
          end
          if yes then
            table.insertIfNeed(tos, move.from)
          end
        end
      end
      if #tos > 0 then
        self.cost_data = tos
        return true
      end
    end
  end,
  on_trigger = function(self, event, target, player, data)
    self.cancel_cost = false
    local tos = self.cost_data
    for _, id in ipairs(tos) do
      if not player:hasSkill(self) or self.cancel_cost then return end
      if not table.contains(player:getTableMark("sk__zhubao-turn"), id) then
        self.cost_data = id
        self:doCost(event, target, player, data)
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    if player.room:askForSkillInvoke(player, self.name) then
      return true
    end
    self.cancel_cost = true
  end,
  on_use = function(self, event, target, player, data)
    local mark = player:getTableMark("sk__zhubao-turn")
    table.insert(mark, self.cost_data)
    player.room:setPlayerMark(player, "sk__zhubao-turn", mark)
    local suits = {}
    for _, move in ipairs(data) do
      if move.from and move.from == self.cost_data then
        for _, info in ipairs(move.moveInfo) do
          if info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip then
            if Fk:getCardById(info.cardId).suit ~= Card.NoSuit then
              table.insertIfNeed(suits, Fk:getCardById(info.cardId).suit)
            end
          end
        end
      end
    end
    local n = 0
    for _, id in ipairs(player:getCardIds("h")) do
      if table.contains(suits, Fk:getCardById(id).suit) then
        n = n + 1
      end
    end
    player:drawCards(n, self.name)
  end,
}
kuaiyue:addSkill(sk__yidu)
kuaiyue:addSkill(sk__zhubao)
Fk:loadTranslationTable{
  ["sk__kuaiyue"] = "蒯越",
  ["#sk__kuaiyue"] = "强谋谨略",

  ["sk__yidu"] = "异度",
  [":sk__yidu"] = "每回合限一次，当你于回合外失去牌后，你可以摸X张牌（X为当前回合角色手牌中花色与这些牌相同的牌数）。",
  ["sk__zhubao"] = "诛暴",
  [":sk__zhubao"] = "你的回合内对每名其他角色限一次，当其他角色失去牌后，你可以摸X张牌（X为你手牌中花色与这些牌相同的牌数）。",

  ["$sk__yidu1"] = "兵不在多，在得人也。",
  ["$sk__yidu2"] = "异度之计，臼犯之谋也。",
  ["$sk__zhubao"] = "诛其无道，蛊而用之。",
  ["~sk__kuaiyue"] = "一家老小，就拜托丞相照顾了……",
}

local yuji = General(extension, "sk__yuji", "qun", 3)
local sk__guhuo = fk.CreateTriggerSkill{
  name = "sk__guhuo",
  anim_type = "control",
  events = {fk.TurnStart},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target ~= player and not target.dead and player:canPindian(target)
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, data, "#sk__guhuo-invoke::"..target.id)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:doIndicate(player.id, {target.id})
    local pindian = player:pindian({target}, self.name)
    if pindian.results[target.id].winner == player then
      if not player.dead and not target.dead then
        if player:getMark("sk__guhuo_cards") == 0 then
          room:setPlayerMark(player, "sk__guhuo_cards", U.getUniversalCards(room, "bt"))
        end
        room:setPlayerMark(player, "sk__guhuo_target", target.id)
        local success, dat = room:askForUseActiveSkill(player, "sk__guhuo_active", "#sk__guhuo-choose::"..target.id, false)
        room:setPlayerMark(player, "sk__guhuo_target", 0)
        if success then
          local card = Fk:cloneCard(Fk:getCardById(dat.cards[1]).name)
          card.skillName = self.name
          room:useCard{
            from = target.id,
            tos = table.map(dat.targets, function(id) return {id} end),
            card = card,
          }
        end
      end
    else
      if not player.dead then
        room:damage{
          from = target,
          to = player,
          damage = 1,
          skillName = self.name,
        }
      end
    end
  end
}
local sk__guhuo_active = fk.CreateActiveSkill{
  name = "sk__guhuo_active",
  expand_pile = function(self,player)
    return player:getTableMark("sk__guhuo_cards")
  end,
  card_num = 1,
  card_filter = function(self, to_select, selected,player)
    if #selected > 0 then return false end
    local mark = player:getTableMark("sk__guhuo_cards")
    if table.contains(mark, to_select) then
      local name = Fk:getCardById(to_select).name
      local card = Fk:cloneCard(name)
      card.skillName = "sk__guhuo"
      local target = Fk:currentRoom():getPlayerById(player:getMark("sk__guhuo_target"))
      return target:canUse(card, {bypass_times = true}) and not target:prohibitUse(card)
    end
  end,
  target_filter =function (self, to_select, selected, selected_cards, card, extra_data, player)
    if #selected_cards == 0 then return false end
    local card = Fk:cloneCard(Fk:getCardById(selected_cards[1]).name)
    card.skillName = "sk__guhuo"
    local target = Fk:currentRoom():getPlayerById(player:getMark("sk__guhuo_target"))
    if card.skill:getMinTargetNum() == 0 or #selected >= card.skill:getMaxTargetNum(target, card) then return false end
    return not target:isProhibited(Fk:currentRoom():getPlayerById(to_select), card) and
    card.skill:modTargetFilter(to_select, selected, player:getMark("sk__guhuo_target"), card, true)
  end,
  feasible = function(self, selected, selected_cards,player)
    if #selected_cards == 0 then return false end
    local card = Fk:cloneCard(Fk:getCardById(selected_cards[1]).name)
    card.skillName = "sk__guhuo"
    local target = Fk:currentRoom():getPlayerById(player:getMark("sk__guhuo_target"))
    return #selected >= card.skill:getMinTargetNum() and #selected <= card.skill:getMaxTargetNum(target, card)
  end,
}
local sk__fulu = fk.CreateTriggerSkill{
  name = "sk__fulu",
  anim_type = "masochism",
  events = {fk.Damaged},
  on_trigger = function(self, event, target, player, data)
    self.cancel_cost = false
    for _ = 1, data.damage do
      if self.cancel_cost or not player:hasSkill(self) then break end
      self:doCost(event, target, player, data)
    end
  end,
  on_cost = function(self, event, target, player, data)
    if player.room:askForSkillInvoke(player, self.name, data) then
      return true
    end
    self.cancel_cost = true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local targets = {}
    room.logic:getEventsByRule(GameEvent.ChangeHp, 3, function (e)
      local damage = e.data[5]
      if damage and damage.from and damage.to == player then
        table.insert(targets, damage.from)
        return true
      end
    end, 1)
    for _, p in ipairs(targets) do
      if not p.dead then
        room:doIndicate(player.id, {p.id})
        if not p:isNude() then
          room:throwCard(table.random(p:getCardIds("he")), self.name, p, p)
        end
      end
    end

    targets = {}
    room.logic:getEventsByRule(GameEvent.Recover, 3, function (e)
      local recover = e.data[1]
      if recover.recoverBy and recover.who == player then
        table.insert(targets, recover.recoverBy)
        return true
      end
    end, 1)
    for _, p in ipairs(targets) do
      if not p.dead then
        p:drawCards(1, self.name)
      end
    end
  end,
}
Fk:addSkill(sk__guhuo_active)
yuji:addSkill(sk__guhuo)
yuji:addSkill(sk__fulu)
Fk:loadTranslationTable{
  ["sk__yuji"] = "于吉",
  ["#sk__yuji"] = "太平道人",

  ["sk__guhuo"] = "蛊惑",
  [":sk__guhuo"] = "其他角色回合开始时，你可以与其拼点：若你赢，视为其使用一张牌名和目标由你指定的基本牌或普通锦囊牌；若你没赢，"..
  "其对你造成1点伤害。",
  ["sk__fulu"] = "符箓",
  [":sk__fulu"] = "当你受到1点伤害后，你可以令最近三次对你造成伤害的角色随机弃置一张牌，最近三次令你回复体力的角色摸一张牌。",
  ["#sk__guhuo-invoke"] = "蛊惑：你可以与 %dest 拼点，若你赢，视为其使用一张你指定牌名和目标的牌，若你没赢，其对你造成1点伤害",
  ["#sk__guhuo-choose"] = "蛊惑：选择 %dest 视为使用的牌和目标",
  ["sk__guhuo_active"] = "蛊惑",

  ["$sk__guhuo1"] = "小伙子，要不要赌赌看哪？",
  ["$sk__guhuo2"] = "看好，这可是老夫得意之处！",
  ["$sk__guhuo3"] = "看起来，你是要有一番大作为的呀！",
  ["$sk__fulu1"] = "早知如此，何必当初呢。",
  ["$sk__fulu2"] = "让你说我为老不尊！",
  ["$sk__fulu3"] = "你小子可好，我记住你了！",
  ["~sk__yuji"] = "老夫不陪你们玩儿了！",
}

local panshu = General(extension, "sk__panshu", "wu", 3, 3, General.Female)
local sk__jinzhi = fk.CreateViewAsSkill{
  name = "sk__jinzhi",
  pattern = ".|.|.|.|.|basic,trick",
  prompt = "#sk__jinzhi",
  interaction = function(self,player)
    local all_names = U.getAllCardNames("bt")
    local names = U.getViewAsCardNames(player, self.name, all_names, {}, player:getTableMark("sk__jinzhi-round"))
    if #names == 0 then return false end
    return U.CardNameBox { choices = names, all_choices = all_names }
  end,
  card_filter = Util.FalseFunc,
  view_as = function(self, cards,player)
    if not self.interaction.data then return end
    local card = Fk:cloneCard(self.interaction.data)
    card:addSubcards(player:getCardIds("h"))
    card.skillName = self.name
    return card
  end,
  before_use = function(self, player, use)
    local mark = player:getTableMark("sk__jinzhi-round")
    table.insert(mark, use.card.trueName)
    player.room:setPlayerMark(player, "sk__jinzhi-round", mark)
  end,
  after_use = function (self, player, use)
    if not player.dead then
      player:drawCards(player:usedSkillTimes(self.name, Player.HistoryRound), self.name)
    end
  end,
  enabled_at_play = function(self, player)
    return not player:isKongcheng() and player:usedSkillTimes(self.name, Player.HistoryRound) < 4
  end,
  enabled_at_response = function(self, player, response)
    return not response and Fk.currentResponsePattern and Exppattern:Parse(Fk.currentResponsePattern):matchExp(self.pattern) and
      not player:isKongcheng() and player:usedSkillTimes(self.name, Player.HistoryRound) < 4
  end,
}
local sk__yuyou = fk.CreateTriggerSkill{
  name = "sk__yuyou",
  anim_type = "control",
  frequency = Skill.Compulsory,
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      for _, move in ipairs(data) do
        if move.to == player.id and move.toArea == Card.PlayerHand and #move.moveInfo > 1 then
          return true
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = {}
    for _, move in ipairs(data) do
      if move.to == player.id and move.toArea == Card.PlayerHand and #move.moveInfo > 1 then
        for _, info in ipairs(move.moveInfo) do
          table.insertIfNeed(cards, info.cardId)
        end
      end
    end
    local card = room:askForCard(player, 1, 1, false, self.name, false,
      ".|.|.|.|.|.|"..table.concat(cards, ","), "#sk__yuyou-ask")
    table.removeOne(cards, card[1])
    local n = #cards
    room:throwCard(cards, self.name, player, player)
    local targets = table.filter(room.alive_players, function(p)
      return p.gender == General.Male or p.gender == General.Bigender
    end)
    if player.dead or #targets == 0 then return end
    local to = room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, 1, "#sk__yuyou-choose:::"..n, self.name, true)
    if #to > 0 then
      to = room:getPlayerById(to[1])
      if #room:askForDiscard(to, n, n, true, self.name, true, ".", "#sk__yuyou-discard:::"..n) < n then
        room:loseHp(to, 1, self.name)
      end
    end
  end,
}
panshu:addSkill(sk__jinzhi)
panshu:addSkill(sk__yuyou)
Fk:loadTranslationTable{
  ["sk__panshu"] = "潘淑",
  ["#sk__panshu"] = "江东神女",

  ["sk__jinzhi"] = "锦织",
  [":sk__jinzhi"] = "每轮限四次，你可以将所有手牌当任意基本牌或普通锦囊牌使用（每轮每种牌名限一次），然后摸X张牌（X为本轮此技能发动次数）。",
  ["sk__yuyou"] = "鱼忧",
  [":sk__yuyou"] = "锁定技，当你一次获得至少两张牌后，你选择保留其中一张，弃置其余的牌，然后你可以令一名男性角色选择一项：1.弃置等量的牌；"..
  "2.失去1点体力。",
  ["#sk__jinzhi"] = "锦织：你可以将所有手牌当任意基本牌或普通锦囊牌使用",
  ["#sk__yuyou-ask"] = "鱼忧：你只能选择保留其中一张牌，弃置其余的牌",
  ["#sk__yuyou-choose"] = "鱼忧：你可以指定一名男性角色，其需弃%arg张牌，否则其失去1点体力",
  ["#sk__yuyou-discard"] = "鱼忧：弃置%arg张牌，否则你失去1点体力",

  ["$sk__jinzhi1"] = "织纫赠君王，锦绣喻江山。",
  ["$sk__jinzhi2"] = "缕因针而入，不因针而急。",
  ["$sk__yuyou1"] = "得鱼则喜，甚而为忧。",
  ["$sk__yuyou2"] = "喜新忘旧，深以为戒。",
  ["~sk__panshu"] = "仲谋，臣妾先走一步……",
}

local zhangrang = General(extension, "sk__zhangrang", "qun", 3)
local sk__taoluan = fk.CreateTriggerSkill{
  name = "sk__taoluan",
  anim_type = "control",
  events = {fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and (data.card.type == Card.TypeBasic or data.card:isCommonTrick()) and data.firstTarget and
      table.every(player.room.alive_players, function(p)
        return not p.dying
      end) and not player:isNude() then
      local all_choices = {}
      if data.card.type == Card.TypeBasic then
        all_choices = U.getAllCardNames("b")
      elseif data.card:isCommonTrick() then
        all_choices = U.getAllCardNames("t")
      end
      local choices = {}
      for _, name in ipairs(all_choices) do
        local card = Fk:cloneCard(name)
        if not table.contains(player:getTableMark("sk__taoluan-round"), card.trueName) and
          name ~= data.card.name and
          target:canUse(card, {bypass_distances = true, bypass_times = true}) and
          (not card.skill:getMinTargetNum() or card.skill:getMinTargetNum() < 2) then
          table.insert(choices, name)
        end
      end
      if #choices > 0 then
        self.cost_data = {choices, all_choices}
        return true
      end
    end
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(player, "sk__taoluan-tmp", self.cost_data)
    local success, dat = room:askForUseActiveSkill(player, "sk__taoluan_active",
      "#sk__taoluan-invoke::"..target.id..":"..data.card:toLogString(), true)
    room:setPlayerMark(player, "sk__taoluan-tmp", 0)
    if success then
      self.cost_data = dat
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local name = self.cost_data.interaction
    local mark = player:getTableMark("sk__taoluan-round")
    table.insert(mark, Fk:cloneCard(name).trueName)
    room:setPlayerMark(player, "sk__taoluan-round", mark)
    room:throwCard(self.cost_data.cards, self.name, player, player)

    room:sendLog{
      type = "#SkChangeCardSkill",
      from = player.id,
      to = { target.id },
      arg = self.name,
      arg2 = data.card:toLogString(),
      arg3 = name,
    }

    local use = room.logic:getCurrentEvent():findParent(GameEvent.UseCard, true)
    if use ~= nil then
      local new_card = Fk:cloneCard(name, data.card.suit, data.card.number)
      local c = table.simpleClone(data.card)
      for k, v in pairs(c) do
        if new_card[k] == nil then
          new_card[k] = v
        end
      end
      if data.card:isVirtual() then
        new_card.subcards = data.card.subcards
      else
        new_card.id = data.card.id
      end
      new_card.skillNames = data.card.skillNames
      new_card.skill = Fk:cloneCard(name).skill
      data.card = new_card
      use.data[1].card = new_card
    end
  end,
}
local sk__taoluan_active = fk.CreateActiveSkill{
  name = "sk__taoluan_active",
  card_num = 1,
  interaction = function(self,player)
    local mark = player:getMark("sk__taoluan-tmp")
    return UI.ComboBox {choices = mark[1], all_choices = mark[2]}
  end,
  card_filter =function (self, to_select, selected, player)
    return #selected == 0 and not player:prohibitDiscard(to_select)
  end,
}
Fk:addSkill(sk__taoluan_active)
zhangrang:addSkill(sk__taoluan)
Fk:loadTranslationTable{
  ["sk__zhangrang"] = "张让",
  ["#sk__zhangrang"] = "窃幸绝禋",

  ["sk__taoluan"] = "滔乱",
  [":sk__taoluan"] = "当一名角色使用基本牌或普通锦囊牌指定目标后，若没有角色处于濒死状态，你可以弃置一张牌，令其使用的牌的效果改为"..
  "由你指定牌名的另一张同类别的牌，每轮每种牌名限一次。",
  ["#sk__taoluan-invoke"] = "滔乱：是否弃置一张牌，将 %dest 使用的%arg效果改为你指定的一张牌？",
  ["sk__taoluan_active"] = "滔乱",
  ["#SkChangeCardSkill"] = "%from 发动了〖%arg〗，将 %to 使用的 %arg2 改为 %arg3",

  ["$sk__taoluan1"] = "这天下洪水滔天，又与我何干？",
  ["$sk__taoluan2"] = "就算是皇上，也要倾听我的心意。",
  ["~sk__zhangrang"] = "臣等死，陛下自爱……",
}

local xinxianying = General(extension, "sk__xinxianying", "wei", 3, 3, General.Female)
local sk__caijian = fk.CreateActiveSkill{
  name = "sk__caijian",
  anim_type = "control",
  card_num = 0,
  target_num = 1,
  prompt = "#sk__caijian",
  derived_piles = "sk__xinxianying_jian",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) - player:getMark("sk__caijian_trigger-phase") < 1
  end,
  card_filter = Util.FalseFunc,
  target_filter =function (self, to_select, selected, selected_cards, card, extra_data, player)
    return #selected == 0 and not Fk:currentRoom():getPlayerById(to_select):isNude()
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    local card = room:askForCardChosen(player, target, "he", self.name, "#sk__caijian_choose::"..target.id)
    local yes = false
    if Fk:getCardById(card).color == Card.Black and
      table.every(player:getPile("sk__xinxianying_jian"), function(id)
        return Fk:getCardById(id).suit ~= Fk:getCardById(card).suit and Fk:getCardById(id).suit ~= Card.NoSuit
      end) then
      yes = true
    end
    player:addToPile("sk__xinxianying_jian", card, true, self.name, player.id)
    if yes and not target.dead then
      target:turnOver()
    end
  end,
}
local sk__caijian_trigger = fk.CreateTriggerSkill{
  name = "#sk__caijian_trigger",
  mute = true,
  events = {fk.Damaged},
  main_skill = sk__caijian,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(sk__caijian) and
      table.find(player.room.alive_players, function(p)
        return not p:isNude()
      end)
  end,
  on_trigger = function(self, event, target, player, data)
    self.cancel_cost = false
    for _ = 1, data.damage do
      if player.dead or self.cancel_cost or
        table.every(player.room.alive_players, function(p)
          return p:isNude()
        end) then return end
      self:doCost(event, target, player, data)
    end
  end,
  on_cost = function(self, event, target, player, data)
    local targets = table.map(table.filter(player.room.alive_players, function(p)
      return not p:isNude()
    end), Util.IdMapper)
    local to = player.room:askForChoosePlayers(player, targets, 1, 1, "#sk__caijian", "sk__caijian", true)
    if #to > 0 then
      self.cost_data = to[1]
      return true
    end
    self.cancel_cost = true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:addPlayerMark(player, "sk__caijian_trigger-phase", 1)
    player:broadcastSkillInvoke("sk__caijian")
    room:notifySkillInvoked(player, "sk__caijian", "masochism")
    sk__caijian:onUse(room, {
      from = player.id,
      tos = {self.cost_data},
    })
  end,
}
local sk__zhishi = fk.CreateActiveSkill{
  name = "sk__zhishi",
  anim_type = "special",
  card_num = 3,
  target_num = 0,
  prompt = "#sk__zhishi",
  expand_pile = "sk__xinxianying_jian",
  can_use = function(self, player)
    return #player:getPile("sk__xinxianying_jian") > 2
  end,
  target_filter = Util.FalseFunc,
  card_filter =function (self, to_select, selected, player)
    return #selected < 3 and player:getPileNameOfId(to_select) == "sk__xinxianying_jian" and
      table.every(selected, function(id)
        return Fk:getCardById(to_select).suit ~= Fk:getCardById(id).suit and Fk:getCardById(to_select).suit ~= Card.NoSuit
      end)
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    room:moveCardTo(effect.cards, Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, self.name, nil, true, player.id)
    if player.dead then return end
    player:drawCards(3,self.name)
    if player.dead then return end
    local skills = {}
    for _, general in ipairs(room.general_pile) do
      local g = Fk.generals[general]
      if g.kingdom == "wei" then
        table.insert(skills, g:getSkillNameList())
      end
    end
    skills = table.filter(table.random(skills), function(s)
      return not player:hasSkill(s, true)
    end)
    if #skills == 0 then return end
    room:handleAddLoseSkills(player, skills, nil, true, false)
  end,
}
sk__caijian:addRelatedSkill(sk__caijian_trigger)
xinxianying:addSkill(sk__caijian)
xinxianying:addSkill(sk__zhishi)
Fk:loadTranslationTable{
  ["sk__xinxianying"] = "辛宪英",
  ["#sk__xinxianying"] = "名门智女",

  ["sk__caijian"] = "才鉴",
  [":sk__caijian"] = "出牌阶段限一次，或当你受到1点伤害后，你可以将一名角色的一张牌置于武将牌上，称为“鉴”，若此“鉴”为黑色且与其他“鉴”的花色"..
  "均不同，你令该角色翻面。",
  ["sk__zhishi"] = "智识",
  [":sk__zhishi"] = "出牌阶段，你可以将三张花色各不相同的“鉴”置入弃牌堆，摸三张牌，然后获得武将牌堆中随机一名魏势力武将的所有技能。",
  ["sk__xinxianying_jian"] = "鉴",
  ["#sk__caijian"] = "才鉴：你可以将一名角色的一张牌置为“鉴”",
  ["#sk__caijian_choose"] = "才鉴：将 %dest 的一张牌置为“鉴”",
  ["#sk__caijian_trigger"] = "才鉴",
  ["#sk__zhishi"] = "智识：你可以移去三张花色不同的“鉴”，摸三张牌并获得一名魏势力武将的技能！",

  ["$sk__caijian1"] = "以人为镜，可鉴忠良。",
  ["$sk__caijian2"] = "狼子野心者，小女子亦能知晓。",
  ["$sk__zhishi1"] = "通今博古，慧眼识人。",
  ["$sk__zhishi2"] = "明以料事，智以料人。",
  ["~sk__xinxianying"] = "乱世乱料，神难自知。",
}

local wuxian = General(extension, "sk__wuxian", "shu", 3, 3, General.Female)
local sk__hechun = fk.CreateActiveSkill{
  name = "sk__hechun",
  anim_type = "control",
  prompt = "#sk__hechun",
  card_num = 0,
  target_num = 0,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0 and
      table.find(Fk:currentRoom().alive_players, function(p) return p ~= player and not p:isNude() end)
  end,
  card_filter = Util.FalseFunc,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local targets = room:getOtherPlayers(player)
    room:doIndicate(player.id, table.map(targets, Util.IdMapper))
    local black, red = {}, {}
    for _, target in ipairs(targets) do
      if player.dead then return end
      if not target.dead and not target:isNude() then
        local card = room:askForCard(target, 1, 1, true, self.name, false, ".", "#sk__hechun-give:"..player.id)
        if Fk:getCardById(card[1]).color == Card.Black then
          table.insert(black, target)
        elseif Fk:getCardById(card[1]).color == Card.Red then
          table.insert(red, target)
        end
        room:moveCardTo(card, Card.PlayerHand, player, fk.ReasonGive, self.name, nil, true, target.id)
      end
    end
    if player.dead then return end
    local choice = room:askForChoice(player, {"sk__hechun_black", "sk__hechun_red", "Cancel"}, self.name)
    if choice == "sk__hechun_black" then
      for _, p in ipairs(black) do
        if not p.dead then
          room:loseHp(p, 1, self.name)
        end
      end
    elseif choice == "sk__hechun_red" then
      for _, p in ipairs(red) do
        if not p.dead and p:isWounded() then
          room:recover({
            who = p,
            num = 1,
            recoverBy = player,
            skillName = self.name,
          })
        end
      end
    end
  end,
}
local sk__daiyan = fk.CreateTriggerSkill{
  name = "sk__daiyan",
  anim_type = "control",
  events = {fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self)
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local to = room:askForChoosePlayers(player, table.map(room.alive_players, Util.IdMapper), 1, 1,
      "#sk__daiyan-choose", self.name, true)
    if #to > 0 then
      self.cost_data = {tos = to}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data.tos[1])
    local mark = player:getTableMark(self.name)
    mark[string.format("%.0f", to.id)] = (mark[string.format("%.0f", to.id)] or 0) + 1
    room:setPlayerMark(player, self.name, mark)
    to:gainAnExtraTurn()
    room:loseHp(to, mark[string.format("%.0f", to.id)], self.name)
  end,
}
wuxian:addSkill(sk__hechun)
wuxian:addSkill(sk__daiyan)
Fk:loadTranslationTable{
  ["sk__wuxian"] = "吴苋",
  ["#sk__wuxian"] = "穆皇后",

  ["sk__hechun"] = "贺春",
  [":sk__hechun"] = "出牌阶段限一次，你可以令所有其他角色依次展示并交给你一张牌，然后你可以令以此法交给你黑色牌的角色各失去1点体力，"..
  "或令以此法交给你红色牌的角色各回复1点体力。",
  ["sk__daiyan"] = "怠宴",
  [":sk__daiyan"] = "回合结束时，你可以令一名角色于此回合结束后执行一个额外回合，并令其失去X点体力（X为你对其发动此技能的次数）。",
  ["#sk__hechun"] = "贺春：令所有其他角色交给你一张牌，然后你可以根据颜色执行效果",
  ["#sk__hechun-give"] = "贺春：交给 %src 一张牌，黑色牌其可以令你失去体力，红色牌其可以令你回复体力",
  ["sk__hechun_black"] = "交出黑色牌的角色各失去1点体力",
  ["sk__hechun_red"] = "交出红色牌的角色各回复1点体力",
  ["#sk__daiyan-choose"] = "怠宴：令一名角色执行一个额外回合，其失去对你其发动此技能次数的体力",

  ["$sk__hechun1"] = "百姓安居乐业，此乃大汉之福。",
  ["$sk__hechun2"] = "新春佳节，众卿可略施薄礼。",
  ["$sk__daiyan1"] = "且在宫中多待几日吧。",
  ["$sk__daiyan2"] = "如此佳节，不妨留下长叙。",
  ["~sk__wuxian"] = "玄德，我来陪你了……",
}

local wenyang = General(extension, "sk__wenyang", "wei", 7)
local sk__jueyong = fk.CreateTriggerSkill{
  name = "sk__jueyong",
  anim_type = "support",
  frequency = Skill.Limited,
  events = {fk.Damage},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target and target == player and data.card and data.card.trueName == "slash" and
      player:getHandcardNum() > player.maxHp and player:usedSkillTimes(self.name, Player.HistoryGame) == 0
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#sk__jueyong-invoke")
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local n = player:getHandcardNum() - player.maxHp
    room:changeMaxHp(player, n)
    if not player.dead and player:isWounded() then
      room:recover({
        who = player,
        num = player:getLostHp(),
        recoverBy = player,
        skillName = self.name,
      })
    end
  end,
}
local sk__choujue = fk.CreateViewAsSkill{
  name = "sk__choujue",
  anim_type = "offensive",
  prompt = "#sk__choujue",
  card_filter = Util.FalseFunc,
  view_as = function(self, cards)
    local card = Fk:cloneCard("slash")
    card.skillName = self.name
    return card
  end,
  before_use = function(self, player, use)
    use.extraUse = true
    player.room:changeMaxHp(player, -1)
    if not player.dead then
      player:drawCards(1, self.name)
    end
  end,
  after_use = function(self, player, use)
    if use.damageDealt and not player.dead then
      local skills = table.filter(player.player_skills, function(s)
        return s:isPlayerSkill(player) and s.visible
      end)
      for _, skill in ipairs(skills) do
        if (skill:isInstanceOf(ActiveSkill) or skill:isInstanceOf(ViewAsSkill)) and
          Fk:translate(":"..skill.name, "zh_Cn"):startsWith("出牌阶段限一次") and
          player:usedSkillTimes(skill.name, Player.HistoryPhase) > 0 then
          player:setSkillUseHistory(skill.name, 0, Player.HistoryPhase)
        end
      end
    end
  end,
  enabled_at_play = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
}
local sk__choujue_targetmod = fk.CreateTargetModSkill{
  name = "#sk__choujue_targetmod",
  bypass_times = function(self, player, skill, scope, card)
    return card and table.contains(card.skillNames, "sk__choujue")
  end,
}
sk__choujue:addRelatedSkill(sk__choujue_targetmod)
wenyang:addSkill(sk__jueyong)
wenyang:addSkill(sk__choujue)
Fk:loadTranslationTable{
  ["sk__wenyang"] = "文鸯",
  ["#sk__wenyang"] = "万众披靡",

  ["sk__jueyong"] = "绝勇",
  [":sk__jueyong"] = "限定技，当你使用【杀】造成伤害后，若你的手牌数大于体力上限，你可以将体力上限调整至手牌数，然后回复体力至体力上限。",
  ["sk__choujue"] = "仇决",
  [":sk__choujue"] = "出牌阶段限一次，你可以减1点体力上限并摸一张牌，视为使用一张【杀】，若此【杀】造成伤害，令你所有出牌阶段限一次的技能"..
  "视为未发动过。",
  ["#sk__jueyong-invoke"] = "绝勇：你将体力上限调整至手牌数，回复体力至体力上限！",
  ["#sk__choujue"] = "仇决：你可以减1点体力上限并摸一张牌，视为使用一张【杀】！",

  ["$sk__jueyong1"] = "鼓角齐鸣，声如裂石穿云！",
  ["$sk__jueyong2"] = "血洒疆场，何惧青山埋骨！",
  ["$sk__choujue1"] = "弑父之仇，今日清算！",
  ["$sk__choujue2"] = "家仇未报，怎可独安！",
  ["~sk__wenyang"] = "半生功业，竟被奸臣所害！……",
}

local zhugezhan = General(extension, "sk__zhugezhan", "shu", 4)
local sk__zuilun = fk.CreateTriggerSkill{
  name = "sk__zuilun",
  anim_type = "control",
  frequency = Skill.Compulsory,
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Finish
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if #room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function(e)
      for _, move in ipairs(e.data) do
        if move.from == player.id and move.moveReason == fk.ReasonDiscard and
        table.find(move.moveInfo, function (info)
          return info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip
        end) then
          return true
        end
      end
    end, Player.HistoryTurn) == 0 then
      player:drawCards(4, self.name)
    elseif #room:getOtherPlayers(player) > 0 then
      local to = room:askForChoosePlayers(player, table.map(room:getOtherPlayers(player), Util.IdMapper), 1, 1,
        "#sk__zuilun1-choose", self.name, false)
      to = room:getPlayerById(to[1])
      to:drawCards(4, self.name)
    end
    if player.dead then return end

    if #room.logic:getEventsOfScope(GameEvent.Recover, 1, function(e)
      local recover = e.data[1]
      return recover.who.id == player.id
    end, Player.HistoryTurn) == 0 then
      room:loseHp(player, 1, self.name)
    elseif #room:getOtherPlayers(player) > 0 then
      local to = room:askForChoosePlayers(player, table.map(room:getOtherPlayers(player), Util.IdMapper), 1, 1,
        "#sk__zuilun2-choose", self.name, false)
      to = room:getPlayerById(to[1])
      room:loseHp(to, 1, self.name)
    end
    if player.dead then return end

    if #room.logic:getEventsOfScope(GameEvent.ChangeHp, 1, function(e)
      local damage = e.data[5]
      return damage and player == damage.from
    end, Player.HistoryTurn) == 0 then
      room:changeMaxHp(player, -1)
    elseif #room:getOtherPlayers(player) > 0 then
      local to = room:askForChoosePlayers(player, table.map(room:getOtherPlayers(player), Util.IdMapper), 1, 1,
        "#sk__zuilun3-choose", self.name, false)
      to = room:getPlayerById(to[1])
      room:changeMaxHp(to, -1)
    end
  end,
}
local sk__fuzhi = fk.CreateTriggerSkill{
  name = "sk__fuzhi",
  frequency = Skill.Wake,
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and
      player:usedSkillTimes(self.name, Player.HistoryGame) == 0 and
      player.phase == Player.Start
  end,
  can_wake = function(self, event, target, player, data)
    return player.hp == 1
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:changeMaxHp(player, 1)
    if player.dead then return end
    if player:isWounded() then
      room:recover({
        who = player,
        num = 1,
        recoverBy = player,
        skillName = self.name,
      })
    end
    if player.dead then return end
    local skills = {}
    for _, s in ipairs(player.player_skills) do
      if s:isPlayerSkill(player) and s.visible then
        table.insert(skills, "-"..s.name)
      end
    end
    room:handleAddLoseSkills(player, table.concat(skills, "|").."|sk__yaozhi|sk__xingyun", nil, true, false)
  end,
}
zhugezhan:addSkill(sk__zuilun)
zhugezhan:addSkill(sk__fuzhi)
zhugezhan:addRelatedSkill("sk__yaozhi")
zhugezhan:addRelatedSkill("sk__xingyun")
Fk:loadTranslationTable{
  ["sk__zhugezhan"] = "诸葛瞻",
  ["#sk__zhugezhan"] = "难堪其重",

  ["sk__zuilun"] = "罪论",
  [":sk__zuilun"] = "锁定技，结束阶段，若你本回合达成了条件，你执行对应效果，否则改为令一名其他角色执行对应效果：<br>"..
  "1.若你本回合没有弃置牌，摸四张牌；<br>"..
  "2.若你本回合未回复过体力，失去1点体力；<br>"..
  "3.若你本回合未造成过伤害，减1点体力上限。",
  ["sk__fuzhi"] = "父志",
  [":sk__fuzhi"] = "觉醒技，准备阶段，若你的体力值为1，你加1点体力上限，回复1点体力，然后失去所有技能，获得〖妖智〗和〖星陨〗。",
  ["#sk__zuilun1-choose"] = "罪论：令一名其他角色摸四张牌",
  ["#sk__zuilun2-choose"] = "罪论：令一名其他角色失去1点体力",
  ["#sk__zuilun3-choose"] = "罪论：令一名其他角色减1点体力上限",

  ["$sk__zuilun1"] = "我有三罪，未能除黄皓、制伯约、守国土。",
  ["$sk__zuilun2"] = "空有其表，溢美其实，吾不堪此实。",
  ["$sk__fuzhi1"] = "承先父之志，兴复汉室！",
  ["$sk__fuzhi2"] = "这就是父亲的力量吗！",
  ["~sk__zhugezhan"] = "我不及父之一二……",
}

local sunru = General(extension, "sk__sunru", "wu", 3, 3, General.Female)
local sk__xiecui = fk.CreateTriggerSkill{
  name = "sk__xiecui",
  anim_type = "control",
  events = {fk.DamageCaused},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target and not target.dead and target == player.room.current and
      #player.room.logic:getActualDamageEvents(2, function(e) return e.data[1].from == target end) == 0 and
      #player:getCardIds("he") > 1
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local success, dat = room:askForUseActiveSkill(player, "sk__xiecui_active", "#sk__xiecui-invoke::"..target.id, true)
    if success then
      self.cost_data = dat
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:doIndicate(player.id, {target.id})
    room:throwCard(self.cost_data.cards, self.name, player, player)
    local n = #room.logic:getEventsOfScope(GameEvent.UseCard, 999, function(e)
      local use = e.data[1]
      return use and use.from == target.id
    end, Player.HistoryTurn)
    if self.cost_data.interaction == "damage+1" then
      data.damage = data.damage + 1
      if not target.dead and n > 0 then
        target:drawCards(n, self.name)
      end
    else
      data.damage = data.damage - 1
      if not target.dead and n > 0 then
        room:askForDiscard(target, n, n, true, self.name, false)
      end
    end
  end,
}
local sk__xiecui_active = fk.CreateActiveSkill{
  name = "sk__xiecui_active",
  card_num = 2,
  target_num = 0,
  interaction = function()
    return UI.ComboBox {choices = {"damage+1", "damage-1"}}
  end,
  card_filter =function (self, to_select, selected, player)
    if Fk:getCardById(to_select).suit ~= Card.NoSuit then
      if #selected == 0 then
        return true
      elseif #selected == 1 then
        return Fk:getCardById(to_select).suit ~= Fk:getCardById(selected[1]).suit
      else
        return false
      end
    end
  end,
}
local sk__youxu = fk.CreateTriggerSkill{
  name = "sk__youxu",
  anim_type = "control",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target.phase == Player.Play and not target.dead and
      target:isWounded() and #target:getCardIds("he") >= target:getLostHp()
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#sk__youxu-invoke::"..target.id..":"..target:getLostHp())
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:doIndicate(player.id, {target.id})
    local n = target:getLostHp()
    local cards = room:askForCardsChosen(player, target, n, n, "he", self.name, "#sk__youxu-card::"..target.id..":"..target:getLostHp())
    local choices = {"peach", "amazing_grace"}
    for i = 2, 1, -1 do
      local card = Fk:cloneCard(choices[i])
      card:addSubcards(cards)
      card.skillName = self.name
      if not target:canUse(card) then
        table.remove(choices, i)
      end
    end
    if #choices == 0 then return end
    local choice = room:askForChoice(player, choices, self.name, "#sk__youxu-choice::"..target.id)
    if choice == "peach" then
      room:useVirtualCard(choice, cards, target, target, self.name, true)
    else
      room:useVirtualCard(choice, cards, target, table.filter(room:getAllPlayers(), function(p)
        local card = Fk:cloneCard("amazing_grace")
        card:addSubcards(cards)
        card.skillName = self.name
        return not target:isProhibited(p, card)
      end), self.name, true)
    end
  end,
}
Fk:addSkill(sk__xiecui_active)
sunru:addSkill(sk__xiecui)
sunru:addSkill(sk__youxu)
Fk:loadTranslationTable{
  ["sk__sunru"] = "孙茹",
  ["#sk__sunru"] = "青翠之莲",

  ["sk__xiecui"] = "撷翠",
  [":sk__xiecui"] = "当一名角色于其回合内首次造成伤害时，你可以弃置两张花色不同的牌并选择一项：1.令此伤害+1，然后其摸X张牌；2.令此伤害-1，"..
  "然后其弃置X张牌。（X为其本回合内已使用的牌数）",
  ["sk__youxu"] = "忧恤",
  [":sk__youxu"] = "一名角色出牌阶段开始时，你可以选择其X张牌，令其将这些牌当【桃】或【五谷丰登】使用（X为其已损失体力值）。",
  ["#sk__xiecui-invoke"] = "撷翠：你可以弃置两张花色不同的牌，令 %dest 造成伤害+1并摸牌，或伤害-1并弃牌",
  ["sk__xiecui_active"] = "撷翠",
  ["damage+1"] = "伤害+1",
  ["damage-1"] = "伤害-1",
  ["#sk__youxu-invoke"] = "忧恤：你可以选择 %dest 的%arg张牌，令其将这些牌当【桃】或【五谷丰登】使用",
  ["#sk__youxu-card"] = "忧恤：选择 %dest 的%arg张牌",
  ["#sk__youxu-choice"] = "忧恤：选择 %dest 用这些牌来转化使用的牌名",

  ["$sk__xiecui1"] = "繁花满江左，翠色遍山川。",
  ["$sk__xiecui2"] = "点点繁华坠，丝丝翠雨落。",
  ["$sk__youxu1"] = "茹虽女子，亦心系百姓。",
  ["$sk__youxu2"] = "周忧济难，望君恤之。",
  ["~sk__sunru"] = "今世缘已尽，来世再做夫妻……",
}

local liuyan = General(extension, "sk__liuyan", "qun", 3)
local sk__zhulu = fk.CreateTriggerSkill{
  name = "sk__zhulu",
  anim_type = "control",
  events = {fk.Damage},
  can_trigger = function(self, event, target, player, data)
    return target and target == player and player:hasSkill(self) and not data.to.dead and not data.to:isNude() and
      table.find(player.room:getOtherPlayers(data.to), function(p)
        return not p.dead
      end)
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#sk__zhulu-invoke::"..data.to.id)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    for _, p in ipairs(room:getOtherPlayers(data.to)) do
      if data.to.dead or data.to:isNude() then return end
      if not p.dead then
        room:doIndicate(p.id, {data.to.id})
        local card = room:askForCardChosen(p, data.to, "he", self.name)
        room:moveCardTo(card, Card.PlayerHand, p, fk.ReasonPrey, self.name, nil, false, p.id)
      end
    end
  end,
}
local sk__limu = fk.CreateActiveSkill{
  name = "sk__limu",
  anim_type = "drawcard",
  card_num = 1,
  target_num = 0,
  prompt = "#sk__limu",
  can_use = function(self, player)
    return not player:hasDelayedTrick("indulgence") and not table.contains(player.sealedSlots, Player.JudgeSlot) and
      player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter =function (self, to_select, selected, player)
    local card = Fk:getCardById(to_select)
    return #selected == 0 and card.suit == Card.Diamond and
      not player:isProhibited(player, Fk:cloneCard("indulgence", card.suit, card.number))
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    room:useVirtualCard("indulgence", effect.cards, player, player, self.name, true)
    if player:isWounded() then
      room:recover{
        who = player,
        num = 1,
        skillName = self.name,
      }
    end
    if not player.dead then
      player:drawCards(Fk:getCardById(effect.cards[1]).number, self.name)
    end
  end,
}
local sk__limu_targetmod = fk.CreateTargetModSkill{
  name = "#sk__limu_targetmod",
  main_skill = sk__limu,
  bypass_times = function(self, player, skill, scope, card, to)
    return player:hasSkill(sk__limu) and #player:getCardIds("j") > 0
  end,
}
sk__limu:addRelatedSkill(sk__limu_targetmod)
liuyan:addSkill(sk__zhulu)
liuyan:addSkill(sk__limu)
Fk:loadTranslationTable{
  ["sk__liuyan"] = "刘焉",
  ["#sk__liuyan"] = "割据之雄",

  ["sk__zhulu"] = "逐鹿",
  [":sk__zhulu"] = "当你对一名角色造成伤害后，你可以令除该角色以外的所有角色各获得其一张牌。",
  ["sk__limu"] = "立牧",
  [":sk__limu"] = "出牌阶段限一次，你可以将一张<font color='red'>♦</font>牌当【乐不思蜀】对你使用，然后回复1点体力并摸X张牌（X为此牌的点数）。"..
  "若你的判定区内有牌，你使用牌无次数限制。",
  ["#sk__zhulu-invoke"] = "逐鹿：是否所有角色各获得 %dest 一张牌？",
  ["#sk__limu"] = "立牧：将一张<font color='red'>♦</font>牌当【乐不思蜀】对你使用，然后回复1点体力并摸此牌点数的牌",
}

local guohuanghou = General(extension, "sk__guohuanghou", "wei", 3, 3, General.Female)
local sk__jiaozhao = fk.CreateActiveSkill{
  name = "sk__jiaozhao",
  anim_type = "control",
  prompt = "#sk__jiaozhao",
  interaction = function(self,player)
    local all_names = U.getAllCardNames("bt")
    local names = {}
    for _, name in ipairs(all_names) do
      local card = Fk:cloneCard(name)
      if card.skill:canUse(player, card, {bypass_times = true, bypass_distances = true}) or
        table.contains({"peach", "ex_nihilo", "foresight", "wd_rice"}, card.trueName) or  --默认目标救救
        card.multiple_targets then
        table.insert(names, name)
      end
    end
    return U.CardNameBox {choices = names, all_choices = all_names}
  end,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter =function (self, to_select, selected, player)
    return #selected == 0 and Fk:currentRoom():getCardArea(to_select) == Card.PlayerHand
  end,
  target_filter =function (self, to_select, selected, selected_cards, card, extra_data, player)
    if #selected_cards == 1 and self.interaction.data then
      local card = Fk:cloneCard(self.interaction.data)
      card:addSubcards(selected_cards)
      if #selected >= card.skill:getMaxTargetNum(player, card) then return false end
      if card.skill:getMinTargetNum() == 2 then
        return not (#selected == 0 and to_select == player.id)
      else
        return to_select ~= player.id
      end
    end
  end,
  feasible = function(self, selected, selected_cards,player)
    if #selected_cards == 1 and self.interaction.data then
      local card = Fk:cloneCard(self.interaction.data)
      card:addSubcards(selected_cards)
      if #selected >= card.skill:getMinTargetNum() and #selected <= card.skill:getMaxTargetNum(player, card) then
        if card.skill:getMinTargetNum() == 0 then
          return #selected > 0 or card.multiple_targets
        else
          return true
        end
      end
    end
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local card = Fk:cloneCard(self.interaction.data)
    card:addSubcards(effect.cards)
    card.skillName = self.name
    if #effect.tos == 0 and card.multiple_targets and card.skill:getMinTargetNum() == 0 then
      effect.tos = table.map(room:getOtherPlayers(player), function(p)
        if card.skill:modTargetFilter(p.id, {}, effect.from, card, true) then
          return p.id
        end
      end)
    end
    room:useCard({
      from = effect.from,
      tos = table.map(effect.tos, function(pid) return { pid } end),
      card = card,
      extraUse = true,
    })
  end,
}
local sk__danxin = fk.CreateTriggerSkill{
  name = "sk__danxin",
  anim_type = "masochism",
  events = {fk.Damaged},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:drawCards(2, self.name)
    if not player.dead and not player:isKongcheng() then
      room:askForUseActiveSkill(player, "sk__jiaozhao", "#sk__jiaozhao", true)
    end
  end,
}
guohuanghou:addSkill(sk__jiaozhao)
guohuanghou:addSkill(sk__danxin)
Fk:loadTranslationTable{
  ["sk__guohuanghou"] = "郭皇后",
  ["#sk__guohuanghou"] = "明元皇后",

  ["sk__jiaozhao"] = "矫诏",
  [":sk__jiaozhao"] = "出牌阶段限一次，你可以将一张手牌当任意基本牌或普通锦囊牌使用，以此法使用的牌无距离和次数限制，且可以无视合法性检测"..
  "选择其他角色为目标（但不能指定你为目标）。",
  ["sk__danxin"] = "殚心",
  [":sk__danxin"] = "当你受到伤害后，你可以摸两张牌，然后你可以发动〖矫诏〗。",
  ["#sk__jiaozhao"] = "矫诏：将一张手牌当任意基本牌或普通锦囊牌使用（无视合法性，但不能指定自己为目标）",
}

local zhaoxiang = General(extension, "sk__zhaoxiang", "shu", 4, 4, General.Female)
local sk__fanghun = fk.CreateViewAsSkill{
  name = "sk__fanghun",
  pattern = "slash,jink",
  prompt = "#sk__fanghun",
  card_filter =function (self, to_select, selected, player)
    if #selected == 0 then
      local c = Fk:getCardById(to_select)
      local card
      if c.trueName == "slash" then
        card = Fk:cloneCard("jink")
      elseif c.trueName == "jink" then
        card = Fk:cloneCard("slash")
      else
        return false
      end
      return (Fk.currentResponsePattern == nil and player:canUse(card)) or
        (Fk.currentResponsePattern and Exppattern:Parse(Fk.currentResponsePattern):match(card))
    end
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then return end
    local c = Fk:getCardById(cards[1])
    local card
    if c.trueName == "slash" then
      card = Fk:cloneCard("jink")
    elseif c.name == "jink" then
      card = Fk:cloneCard("slash")
    end
    card.skillName = self.name
    card:addSubcards(cards)
    return card
  end,
}
local sk__fanghun_trigger = fk.CreateTriggerSkill{
  name = "#sk__fanghun_trigger",
  main_skill = sk__fanghun,
  mute = true,
  events = {fk.CardUsing, fk.CardResponding},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(sk__fanghun) and table.contains(data.card.skillNames, "sk__fanghun") then
      local id
      if event == fk.CardUsing then
        if data.card.trueName == "slash" then
          id = data.tos[1][1]
        elseif data.card.name == "jink" then
          if data.responseToEvent then
            id = data.responseToEvent.from  --jink
          end
        end
      elseif event == fk.CardResponding then
        if data.responseToEvent then
          if data.responseToEvent.from == player.id then
            id = data.responseToEvent.to  --duel used by zhaoyun
          else
            id = data.responseToEvent.from  --savsavage_assault, archery_attack, passive duel

            --TODO: Lenovo shu zhaoyun may chongzhen liubei when responding to jijiang
          end
        end
      end
      if id ~= nil then
        self.cost_data = id
        return not player.room:getPlayerById(id):isKongcheng()
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, "sk__fanghun", nil, "#sk__fanghun-invoke::"..self.cost_data)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data)
    player:broadcastSkillInvoke("sk__fanghun")
    room:notifySkillInvoked(player, "sk__fanghun", "offensive")
    room:doIndicate(player.id, {to.id})
    local card = room:askForCardChosen(player, to, "h", "sk__fanghun")
    room:moveCardTo(card, Card.PlayerHand, player, fk.ReasonPrey, "sk__fanghun", nil, false, player.id)
  end,
}
local sk__fuhan = fk.CreateTriggerSkill{
  name = "sk__fuhan",
  anim_type = "special",
  events = {fk.CardUseFinished},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.card and data.card:isVirtual() and
      data.card.subcards and #data.card.subcards > 0 and
      player:usedSkillTimes(self.name, Player.HistoryTurn) == 0
  end,
  on_cost = function (self,event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#sk__fuhan-invoke")
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local skills = {}
    for _, general in ipairs(room.general_pile) do
      local g = Fk.generals[general]
      if g.kingdom == "shu" then
        table.insertTableIfNeed(skills, g:getSkillNameList())
      end
    end
    skills = table.filter(skills, function(s)
      return not player:hasSkill(s, true)
    end)
    if #skills == 0 then return end
    room:handleAddLoseSkills(player, table.random(skills), nil, true, false)
  end,
}
sk__fanghun:addRelatedSkill(sk__fanghun_trigger)
zhaoxiang:addSkill(sk__fanghun)
zhaoxiang:addSkill(sk__fuhan)
Fk:loadTranslationTable{
  ["sk__zhaoxiang"] = "赵襄",
  ["#sk__zhaoxiang"] = "傲雪寒梅",

  ["sk__fanghun"] = "芳魂",
  [":sk__fanghun"] = "你可以将【杀】当【闪】、【闪】当【杀】使用或打出，然后你可以获得对方的一张牌。",
  ["sk__fuhan"] = "扶汉",
  [":sk__fuhan"] = "每回合限一次，当你使用转化的牌后，你可以随机获得武将牌堆中蜀势力武将的一个技能。",
  ["#sk__fanghun"] = "芳魂：你可以将【杀】当【闪】、【闪】当【杀】使用或打出，然后你可以获得对方的一张牌",
  ["#sk__fanghun-invoke"] = "芳魂：你可以获得 %dest 的一张手牌",
  ["#sk__fanghun_trigger"] = "芳魂",
  ["#sk__fuhan-invoke"] = "扶汉：是否随机获得一个蜀势力武将技能？",

  ["$sk__fanghun1"] = "心如寒梅，不惧严霜。",
  ["$sk__fanghun2"] = "芳华易逝，蜀魂不灭！",
  ["$sk__fuhan1"] = "蜀汉的先辈们，请赐予我力量。",
  ["$sk__fuhan2"] = "父亲，我会继承你的意志。",
  ["~sk__zhaoxiang"] = "蜀汉的命运，真的无法改变吗？",
}

local lvfan = General(extension, "sk__lvfan", "wu", 3)
local sk__diaodu = fk.CreateTriggerSkill{
  name = "sk__diaodu",
  anim_type = "control",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Start
  end,
  on_cost = function(self, event, target, player, data)
    local _, dat = player.room:askForUseActiveSkill(player, "sk__diaodu_active", "#sk__diaodu-invoke", true, nil, false)
    if dat then
      self.cost_data = dat
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local target1, target2 = room:getPlayerById(self.cost_data.targets[1]), room:getPlayerById(self.cost_data.targets[2])
    local n = 0
    if self.cost_data.interaction == "sk__diaodu_hand" then
      n = math.abs(target1:getHandcardNum() - target2:getHandcardNum())
      U.swapHandCards(room, player, target1, target2, self.name)
    else
      local cards1 = table.clone(target1:getCardIds("e"))
      local cards2 = table.clone(target2:getCardIds("e"))
      n = math.abs(#cards1 - #cards2)
      U.swapCards(room, player, target1, target2, cards1, cards2, self.name, Card.PlayerEquip)
    end
    if n > 0 and not player.dead then
      room:askForDiscard(player, n, n, true, self.name, false)
    end
  end,
}
local sk__diaodu_active = fk.CreateActiveSkill{
  name = "sk__diaodu_active",
  card_num = 0,
  target_num = 2,
  interaction = function()
    return UI.ComboBox {choices = {"sk__diaodu_hand", "sk__diaodu_equip"}}
  end,
  card_filter = Util.FalseFunc,
  target_filter =function (self, to_select, selected, selected_cards, card, extra_data, player)
    if #selected == 0 then
      return true
    elseif #selected == 1 then
      local target1 = Fk:currentRoom():getPlayerById(selected[1])
      local target2 = Fk:currentRoom():getPlayerById(to_select)
      if self.interaction.data == "sk__diaodu_hand" then
        return not (target1:isKongcheng() and target2:isKongcheng())
      elseif self.interaction.data == "sk__diaodu_equip" then
        return not (#target1:getCardIds("e") == 0 and #target2:getCardIds("e") == 0)
      end
    end
  end,
}
local sk__diancai = fk.CreateTriggerSkill{
  name = "sk__diancai",
  anim_type = "support",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Finish
  end,
  on_cost = function(self, event, target, player, data)
    local tos = player.room:askForChoosePlayers(player, table.map(player.room.alive_players, Util.IdMapper), 2, 2,
      "#sk__diancai-choose", self.name, true)
    if #tos == 2 then
      self.cost_data = tos
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:sortPlayersByAction(self.cost_data)
    local target1, target2 = room:getPlayerById(self.cost_data[1]), room:getPlayerById(self.cost_data[2])
    local n1, n2 = 0, 0
    room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function(e)
      for _, move in ipairs(e.data) do
        if move.from == target1.id then
          for _, info in ipairs(move.moveInfo) do
            if info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip then
              n2 = n2 + 1
            end
          end
        elseif move.from == target2.id then
          for _, info in ipairs(move.moveInfo) do
            if info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip then
              n1 = n1 + 1
            end
          end
        end
      end
      return false
    end, Player.HistoryTurn)
    if n1 > 0 then
      target1:drawCards(n1, self.name)
    end
    if n2 > 0 and not target2.dead then
      target2:drawCards(n2, self.name)
    end
  end,
}
Fk:addSkill(sk__diaodu_active)
lvfan:addSkill(sk__diaodu)
lvfan:addSkill(sk__diancai)
Fk:loadTranslationTable{
  ["sk__lvfan"] = "吕范",
  ["#sk__lvfan"] = "忠笃亮直",

  ["sk__diaodu"] = "调度",
  [":sk__diaodu"] = "准备阶段，你可以指定两名角色，令这些角色交换手牌或装备区里的牌，然后你弃置X张牌（X为交换的牌数之差）。",
  ["sk__diancai"] = "典财",
  [":sk__diancai"] = "结束阶段，你可以指定两名角色，令这些角色摸等同于对方于本回合内失去牌数的牌。",
  ["#sk__diaodu-invoke"] = "调度：你可以令两名角色交换手牌或交换装备，然后你弃置交换牌数之差的牌",
  ["sk__diaodu_active"] = "调度",
  ["sk__diaodu_hand"] = "交换手牌",
  ["sk__diaodu_equip"] = "交换装备",
  ["#sk__diancai-choose"] = "典财：你可以令两名角色摸对方本回合失去过的牌数张牌",
}

local hetaihou = General(extension, "sk__hetaihou", "qun", 3, 3, General.Female)
local sk__zhendu = fk.CreateTriggerSkill{
  name = "sk__zhendu",
  anim_type = "offensive",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target.phase == Player.Play and player:hasSkill(self) and not target.dead
  end,
  on_cost = function(self, event, target, player, data)
    local prompt = "#sk__zhendu1-invoke::"..target.id
    if target == player then
      prompt = "#sk__zhendu2-invoke"
    end
    return player.room:askForSkillInvoke(player, self.name, nil, prompt)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:doIndicate(player.id, {target.id})
    if target ~= player then
      room:loseHp(target, 1, self.name)
    end
    if not target.dead then
      room:setPlayerMark(target, "@@sk__zhendu-turn", 1)
    end
  end,
}
local sk__zhendu_trigger = fk.CreateTriggerSkill{
  name = "#sk__zhendu_trigger",
  mute = true,
  events = {fk.DamageCaused},
  can_trigger = function(self, event, target, player, data)
    return target and target.phase ~= Player.NotActive and player:usedSkillTimes("sk__zhendu", Player.HistoryTurn) > 0 and
      not data.chain and data.to ~= player
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    data.damage = data.damage + 1
  end,
}
local sk__qiluan = fk.CreateTriggerSkill{
  name = "sk__qiluan",
  anim_type = "offensive",
  events = {fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and not target.dead and
      table.find(player.room:getOtherPlayers(target), function(p)
        return not target:isProhibited(p, Fk:cloneCard("slash"))
      end)
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local targets = table.map(table.filter(room:getOtherPlayers(target), function(p)
      return not target:isProhibited(p, Fk:cloneCard("slash"))
    end), Util.IdMapper)
    local to = room:askForChoosePlayers(player, targets, 1, 1, "#sk__qiluan-choose::"..target.id, self.name, true, true)
    if #to > 0 then
      self.cost_data = to[1]
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:doIndicate(player.id, {target.id})
    room:useVirtualCard("slash", nil, target, room:getPlayerById(self.cost_data), self.name, true)
    if not player.dead then
      local n = #player.room.logic:getEventsOfScope(GameEvent.ChangeHp, 999, function(e)
        return not (e.data[3] == "damage" and e.data[5].isVirtualDMG)
      end, Player.HistoryTurn)
      if n > 0 then
        player:drawCards(n, self.name)
      end
    end
  end,
}
sk__zhendu:addRelatedSkill(sk__zhendu_trigger)
hetaihou:addSkill(sk__zhendu)
hetaihou:addSkill(sk__qiluan)
Fk:loadTranslationTable{
  ["sk__hetaihou"] = "何太后",
  ["#sk__hetaihou"] = "饮鸩弄权",

  ["sk__zhendu"] = "鸩毒",
  [":sk__zhendu"] = "一名角色的出牌阶段开始时，你可以令其于本回合内对除你以外的角色造成的伤害+1，若该角色不为你，你令其失去1点体力。",
  ["sk__qiluan"] = "戚乱",
  [":sk__qiluan"] = "一名角色的回合结束时，你可以令其视为对你指定的另一名角色使用【杀】，然后你摸X张牌（X为所有角色于本回合内体力改变的次数）。",
  ["#sk__zhendu1-invoke"] = "鸩毒：是否令 %dest 失去1点体力，其本回合对除你以外的角色造成伤害+1？",
  ["#sk__zhendu2-invoke"] = "鸩毒：是否令你本回合对其他角色造成伤害+1？",
  ["@@sk__zhendu-turn"] = "鸩毒",
  ["#sk__qiluan-choose"] = "戚乱：你可以令 %dest 视为对你选择的角色使用【杀】，然后你摸牌",
}

local zhangyi = General(extension, "sk__zhangyi", "shu", 4)
local sk__wurong = fk.CreateActiveSkill{
  name = "sk__wurong",
  anim_type = "control",
  card_num = 0,
  target_num = 1,
  prompt = "#sk__wurong",
  can_use = function (self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter =function (self, to_select, selected, selected_cards, card, extra_data, player)
    return #selected == 0 and to_select ~= player.id and not Fk:currentRoom():getPlayerById(to_select):isKongcheng()
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    local card = room:askForCardChosen(player, target, "h", self.name, "#sk__wurong-choose::"..target.id)
    local type = Fk:getCardById(card):getTypeString()
    target:showCards(card)
    if player.dead or player:isKongcheng() then return end
    local card2 = room:askForDiscard(player, 1, 1, false, self.name, true, ".", "#sk__wurong-discard::"..target.id..":"..type, true)
    if #card2 == 0 then return end
    room:throwCard(card2, self.name, player, player)
    if Fk:getCardById(card2[1]):getTypeString() == type then
      if player.dead then return end
      if table.contains(target:getCardIds("h"), card) then
        room:moveCardTo(card, Card.PlayerHand, player, fk.ReasonPrey, self.name, nil, true, player.id)
      end
      if not player.dead and not target.dead and not target:isKongcheng() and
        room:askForSkillInvoke(player, self.name, nil, "#sk__wurong-invoke::"..target.id) then
        player:broadcastSkillInvoke(self.name)
        room:notifySkillInvoked(player, self.name)
        room:doIndicate(player.id, {target.id})
        self:onUse(room, {
          from = player.id,
          tos = {target.id},
        })
      end
    elseif not target.dead then
      if not player.dead then
        local skills = {}
        for _, s in ipairs(target.player_skills) do
          if s:isPlayerSkill(target) and s.frequency ~= Skill.Compulsory and s.frequency ~= Skill.Wake then
            table.insertIfNeed(skills, s.name)
          end
        end
        if #skills > 0 then
          local choice = room:askForChoice(player, skills, self.name, "#sk__wurong-choice::"..target.id)
          local mark = target:getTableMark("@sk__wurong-turn")
          table.insertIfNeed(mark, choice)
          room:setPlayerMark(target, "@sk__wurong-turn", mark)
        end
      end
      room:damage({
        from = player,
        to = target,
        damage = 1,
        skillName = self.name,
      })
    end
  end,
}
local sk__wurong_invalidity = fk.CreateInvaliditySkill {
  name = "#sk__wurong_invalidity",
  invalidity_func = function(self, from, skill)
    return skill:isPlayerSkill(from) and table.contains(from:getTableMark("@sk__wurong-turn"), skill.name)
  end
}
sk__wurong:addRelatedSkill(sk__wurong_invalidity)
zhangyi:addSkill(sk__wurong)
Fk:loadTranslationTable{
  ["sk__zhangyi"] = "张嶷",
  ["#sk__zhangyi"] = "忠节通壮",

  ["sk__wurong"] = "怃戎",
  [":sk__wurong"] = "出牌阶段限一次，你可以展示一名其他角色的一张手牌，然后你可以弃置一张手牌，若这两张牌的类别：不同，你令其一个非锁定技于"..
  "本回合内无效，并对其造成1点伤害；相同，你获得其展示的牌，然后你可以对其重复此流程。",
  ["#sk__wurong"] = "怃戎：展示一名角色一张手牌，然后你可以弃置一张手牌，根据类别执行效果",
  ["#sk__wurong-choose"] = "怃戎：展示 %dest 的一张手牌",
  ["#sk__wurong-discard"] = "怃戎：你可以弃置一张手牌<br>若为%arg，你获得 %dest 的展示牌并可以重复流程<br>"..
  "若不为%arg，令其一个非锁定技本回合无效并对其造成1点伤害",
  ["#sk__wurong-invoke"] = "怃戎：是否继续对 %dest 发动“怃戎”？",
  ["#sk__wurong-choice"] = "怃戎：令 %dest 的一个技能本回合无效并对其造成1点伤害！",
  ["@sk__wurong-turn"] = "技能失效",
}

local caochun = General(extension, "sk__caochun", "wei", 4)
local sk__shanjia = fk.CreateTriggerSkill{
  name = "sk__shanjia",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events = {fk.CardUsing},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) then
      if data.card.trueName == "slash" then
        return #player:getEquipments(Card.SubtypeOffensiveRide) == 0
      elseif data.card:isCommonTrick() and not table.contains({"iron_chain", "collateral", "nullification"}, data.card.trueName) then
        return #player:getEquipments(Card.SubtypeDefensiveRide) == 0
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    data.additionalEffect = (data.additionalEffect or 0) + 1
  end,
}
local sk__shanjia_distance = fk.CreateDistanceSkill{
  name = "#sk__shanjia_distance",
  frequency = Skill.Compulsory,
  main_skill = sk__shanjia,
  correct_func = function(self, from, to)
    if from:hasSkill(sk__shanjia) and #from:getEquipments(Card.SubtypeOffensiveRide) == 0 then
      return -2
    end
    if to:hasSkill(sk__shanjia) and #to:getEquipments(Card.SubtypeDefensiveRide) == 0 then
      return 2
    end
    return 0
  end,
}
sk__shanjia:addRelatedSkill(sk__shanjia_distance)
caochun:addSkill(sk__shanjia)
Fk:loadTranslationTable{
  ["sk__caochun"] = "曹纯",
  ["#sk__caochun"] = "虎豹骑首",

  ["sk__shanjia"] = "缮甲",
  [":sk__shanjia"] = "锁定技，若你的装备区内没有进攻坐骑牌，你计算与其他角色的距离-2，你使用的【杀】额外结算一次；若你的装备区内没有防御坐骑牌，"..
  "其他角色计算与你的距离+2，你使用的普通锦囊牌额外结算一次（【铁锁连环】、【借刀杀人】、【无懈可击】除外）。",
}

local shamoke = General(extension, "sk__shamoke", "shu", 4)
local sk__jilis = fk.CreateTriggerSkill{
  name = "sk__jilis",
  anim_type = "drawcard",
  events = {fk.CardUseFinished, fk.CardRespondFinished},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.card.type ~= Card.TypeTrick and
      table.find(player.room:getOtherPlayers(player), function(p)
        return player:inMyAttackRange(p) and not p:isNude()
      end)
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#sk__jilis-invoke")
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local n = 0
    local targets = table.filter(room:getOtherPlayers(player), function(p)
      return player:inMyAttackRange(p)
    end)
    room:doIndicate(player.id, table.map(targets, Util.IdMapper))
    for _, p in ipairs(targets) do
      if not p.dead and not p:isNude() then
        n = n + 1
        local card = table.random(p:getCardIds("he"))
        room:throwCard(card, self.name, p, p)
      end
    end
    if not player.dead and n > 0 and
      #room.logic:getEventsOfScope(GameEvent.UseCard, 999, function(e)
        local use = e.data[1]
        return use and use.from == player.id
      end, Player.HistoryTurn) <= player:getAttackRange() then
      player:drawCards(n, self.name)
    end
  end,
}
shamoke:addSkill(sk__jilis)
Fk:loadTranslationTable{
  ["sk__shamoke"] = "沙摩柯",
  ["#sk__shamoke"] = "五溪蛮王",

  ["sk__jilis"] = "蒺藜",
  [":sk__jilis"] = "当你使用或打出基本牌或装备牌后，你可以令攻击范围内的其他角色各随机弃置一张牌，然后若你本回合使用的牌数不大于你的攻击范围，"..
  "你摸X张牌（X为本次弃置牌的角色数）。",
  ["#sk__jilis-invoke"] = "蒺藜：是否令攻击范围内的角色各随机弃置一张牌，你摸牌？",
}

local lingcao = General(extension, "sk__lingcao", "wu", 4)
local sk__dujin = fk.CreateTriggerSkill{
  name = "sk__dujin",
  mute = true,
  frequency = Skill.Compulsory,
  events = {fk.TargetSpecified, fk.CardEffectCancelledOut},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) and player.phase == Player.Play and data.card.trueName == "slash" then
      local n = #player.room.logic:getEventsOfScope(GameEvent.UseCard, 2, function(e)
        return e.data[1].from == player.id and e.data[1].card.trueName == "slash"
      end, Player.HistoryPhase)
      if event == fk.TargetSpecified then
        return n == 1
      elseif event == fk.CardEffectCancelledOut then
        return n > 1
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TargetSpecified then
      player:broadcastSkillInvoke(self.name)
      room:notifySkillInvoked(player, self.name, "offensive")
      data.additionalDamage = (data.additionalDamage or 0) + 1
      data.disresponsive = true
    else
      player:broadcastSkillInvoke(self.name)
      room:notifySkillInvoked(player, self.name, "negative")
      room:doIndicate(data.to, {player.id})
      room:damage{
        from = room:getPlayerById(data.to),
        to = player,
        damage = 1,
        skillName = self.name,
      }
    end
  end,
}
local sk__dujin_targetmod = fk.CreateTargetModSkill{
  name = "#sk__dujin_targetmod",
  bypass_times = function(self, player, skill, scope)
    return player:hasSkill(sk__dujin) and skill.trueName == "slash_skill" and scope == Player.HistoryPhase
  end,
}
sk__dujin:addRelatedSkill(sk__dujin_targetmod)
lingcao:addSkill(sk__dujin)
Fk:loadTranslationTable{
  ["sk__lingcao"] = "凌操",
  ["#sk__lingcao"] = "轻舟激进",

  ["sk__dujin"] = "独进",
  [":sk__dujin"] = "锁定技，你使用【杀】无次数限制。你于出牌阶段内使用的第一张【杀】伤害+1且不能被【闪】响应，其余的【杀】被其他角色使用【闪】"..
  "响应后，其对你造成1点伤害。",
}

local zhaoyanw = General(extension, "sk__zhaoyanw", "wu", 3, 3, General.Female)
local sk__sanjue = fk.CreateActiveSkill{
  name = "sk__sanjue",
  anim_type = "support",
  frequency = Skill.Compulsory,  --又是锁定主动技
  prompt = "#sk__sanjue",
  card_num = 0,
  target_num = 1,
  can_use = function(self, player)
    return #player:getTableMark("@[SkSkills]sk__sanjue") > 0
  end,
  card_filter = Util.FalseFunc,
  target_filter =function (self, to_select, selected, selected_cards, card, extra_data, player)
    return #selected == 0 and table.find(player:getTableMark("@[SkSkills]sk__sanjue"), function(s)
      return not Fk:currentRoom():getPlayerById(to_select):hasSkill(s, true)
    end)
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    local skills = player:getMark("@[SkSkills]sk__sanjue")
    local choices = table.simpleClone(skills)
    for _, skill in ipairs(target.player_skills) do
      table.removeOne(choices, skill.name)
    end
    local result = room:askForCustomDialog(player, self.name,
      "packages/utility/qml/ChooseSkillBox.qml", {
      choices, 1, 1, "#sk__sanjue-choice::"..target.id
    })
    local skill = ""
    if result == "" then
      skill = table.random(choices)
    end
    local choice = json.decode(result)
    if #choice > 0 then
      skill = choice[1]
    else
      skill = table.random(choices)
    end
    table.removeOne(skills, skill)
    room:setPlayerMark(player, "@[SkSkills]sk__sanjue", skills)
    room:handleAddLoseSkills(target, skill, nil, true, false)
  end,
}
local sk__sanjue_trigger = fk.CreateTriggerSkill{
  name = "#sk__sanjue_trigger",
  mute = true,
  frequency = Skill.Compulsory,
  events = {fk.CardUsing},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(sk__sanjue) then
      local n = #player.room.logic:getEventsOfScope(GameEvent.UseCard, 4, function(e)
        local use = e.data[1]
        return use.from and use.from == player.id and use.card.name == data.card.trueName
      end, Player.HistoryGame)
      return n == 1 or n == 3
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke("sk__sanjue")
    room:notifySkillInvoked(player, "sk__sanjue", "drawcard")
    player:drawCards(1, "sk__sanjue")
    if player.dead then return end
    local mark = player:getTableMark("@[SkSkills]sk__sanjue")
    local skills = {}
    for _, general in ipairs(room.general_pile) do
      local g = Fk.generals[general]
      if g.kingdom == "wu" then
        table.insertTableIfNeed(skills, g:getSkillNameList())
      end
    end
    if #skills == 0 then return end
    local skill = table.random(skills)
    table.insert(mark, skill)
    room:setPlayerMark(player, "@[SkSkills]sk__sanjue", mark)
  end,

  refresh_events = {fk.EventLoseSkill},
  can_refresh = function (self, event, target, player, data)
    return target == player and data == sk__sanjue
  end,
  on_refresh = function (self, event, target, player, data)
    player.room:setPlayerMark(player, "@[SkSkills]sk__sanjue", 0)
  end,
}
sk__sanjue:addRelatedSkill(sk__sanjue_trigger)
zhaoyanw:addSkill(sk__sanjue)
Fk:loadTranslationTable{
  ["sk__zhaoyanw"] = "赵嫣",
  ["#sk__zhaoyanw"] = "锦绘山河",

  ["sk__sanjue"] = "三绝",
  [":sk__sanjue"] = "锁定技，当你第一次或第三次使用同名牌时，你摸一张牌，然后从武将牌堆的吴势力武将技能中随机获得一个储备技能。出牌阶段，"..
  "你可以令一名角色获得一个储备技能。",
  ["#sk__sanjue"] = "三绝：令一名角色获得一个储备技能",
  ["@[SkSkills]sk__sanjue"] = "三绝",
  ["#sk__sanjue-choice"] = "三绝：选择令 %dest 获得的技能",

  ["$sk__sanjue1"] = "方帛锦绣，五岳河海，此谓针绝。",
  ["$sk__sanjue2"] = "大则盈尺，小则方寸，此谓机绝。",
  ["$sk__sanjue3"] = "薄如蝉翼，轻赛寒烟，此谓丝绝。",
  ["~sk__zhaoyanw"] = "三绝之艺，终究是要失传了吗？",
}

local himiko = General(extension, "sk__himiko", "qun", 3, 3, General.Female)
local sk__canshi = fk.CreateTriggerSkill{
  name = "sk__canshi",
  anim_type = "drawcard",
  events = {fk.HpRecover, fk.MaxHpChanged, fk.EventAcquireSkill, fk.Damage},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and target and target ~= player and not target.dead then
      if event == fk.HpRecover then
        return true
      elseif event == fk.MaxHpChanged then
        return data.num > 0
      elseif event == fk.EventAcquireSkill then
        return player.room:getTag("RoundCount") and data:isPlayerSkill(target) and data.visible
      elseif event == fk.Damage then
        return data.to == player
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#sk__canshi-invoke::"..target.id)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:doIndicate(player.id, {target.id})
    room:addPlayerMark(target, "@sk__canshi", 1)
    room:broadcastProperty(target, "MaxCards")
    player:drawCards(2, self.name)
  end,
}
local sk__canshi_maxcards = fk.CreateMaxCardsSkill{
  name = "#sk__canshi_maxcards",
  correct_func = function(self, player)
    return -player:getMark("@sk__canshi")
  end,
}
local sk__xianji = fk.CreateTriggerSkill{
  name = "sk__xianji",
  anim_type = "control",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Start and
      table.find(player.room:getOtherPlayers(player), function(p)
        return p:getMark("@sk__canshi") > p.maxHp and p:usedSkillTimes("sk__canshi", Player.HistoryGame) == 0
      end)
  end,
  on_cost = function(self, event, target, player, data)
    local targets = table.map(table.filter(player.room:getOtherPlayers(player), function(p)
      return p:getMark("@sk__canshi") > p.maxHp and p:usedSkillTimes("sk__canshi", Player.HistoryGame) == 0
    end), Util.IdMapper)
    local to = player.room:askForChoosePlayers(player, targets, 1, 1, "#sk__xianji-choose", self.name, true)
    if #to > 0 then
      self.cost_data = to[1]
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data)
    local n = to:getMark("@sk__canshi")
    room:setPlayerMark(to, "@sk__canshi", 0)
    room:broadcastProperty(to, "MaxCards")
    room:changeMaxHp(player, n)
    if not player.dead and player:isWounded() then
      room:recover({
        who = player,
        num = math.min(n, player:getLostHp()),
        recoverBy = player,
        skillName = self.name,
      })
    end
    if not player.dead and not to.dead then
      local skills1 = table.map(table.filter(player.player_skills, function(s)
        return s:isPlayerSkill(player) and s.visible
      end), function(s)
        return s.name
      end)
      local skills2 = table.map(table.filter(to.player_skills, function(s)
        return s:isPlayerSkill(player) and s.visible
      end), function(s)
        return s.name
      end)
      room:handleAddLoseSkills(player, "-"..table.concat(skills1, "|-").."|"..table.concat(skills2, "|"), nil, true, false)
      if not to.dead then
        room:handleAddLoseSkills(to, "-"..table.concat(skills2, "|-").."|"..table.concat(skills1, "|"), nil, true, false)
      end
    end
  end,
}
sk__canshi:addRelatedSkill(sk__canshi_maxcards)
himiko:addSkill(sk__canshi)
himiko:addSkill(sk__xianji)
Fk:loadTranslationTable{
  ["sk__himiko"] = "卑弥呼",
  ["#sk__himiko"] = "邪马台女王",

  ["sk__canshi"] = "蚕食",
  [":sk__canshi"] = "当其他角色回复体力/增加体力上限/获得技能/对你造成伤害后，你可以令其获得1枚“蚕食”标记，然后你摸两张牌。拥有“蚕食”标记的角色"..
  "手牌上限-X（X为其“蚕食”标记数）。",
  ["sk__xianji"] = "献祭",
  [":sk__xianji"] = "准备阶段，你可以选择一名“蚕食”标记数大于其体力上限的其他角色，移除其所有“蚕食”标记，若如此做，你加X点体力上限并"..
  "回复X点体力（X为目标角色拥有的技能数），然后你与其交换所有技能，且你本局游戏不能成为〖献祭〗的目标。",
  ["@sk__canshi"] = "蚕食",
  ["#sk__canshi-invoke"] = "蚕食：是否摸两张牌，并令 %dest 获得“蚕食”标记？",
  ["#sk__xianji-choose"] = "献祭：你可以移除一名角色的“蚕食”标记，回复体力并与其交换所有技能！",
}

local wutugu = General(extension, "sk__wutugu", "qun", 6)
local sk__hanyong = fk.CreateTriggerSkill{
  name = "sk__hanyong",
  mute = true,
  frequency = Skill.Compulsory,
  events = {fk.CardEffectCancelledOut, fk.PreCardEffect, fk.DamageInflicted},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      if event == fk.CardEffectCancelledOut then
        return player:getEquipment(Card.SubtypeWeapon) == nil and
          #player:getAvailableEquipSlots(Card.SubtypeWeapon) > 0 and data.from == player.id
          and data.card.trueName == "slash" and not player.room:getPlayerById(data.to).dead
      elseif player:getEquipment(Card.SubtypeArmor) == nil and
        #player:getAvailableEquipSlots(Card.SubtypeArmor) > 0 and
        player:getMark(fk.MarkArmorNullified) == 0 then
        if event == fk.PreCardEffect then
          return player.id == data.to and table.contains({"slash", "savage_assault", "archery_attack"}, data.card.name)
        elseif event == fk.DamageInflicted then
          return target == player and data.damageType == fk.FireDamage
        end
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.CardEffectCancelledOut then
      local room = player.room
      local cards = room:askForDiscard(player, 2, 2, true, self.name, true, ".", "#axe-invoke::"..data.to, true)
      if #cards > 0 then
        self.cost_data = cards
        return true
      end
    else
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    player:broadcastSkillInvoke(self.name)
    local room = player.room
    if event == fk.CardEffectCancelledOut then
      room:notifySkillInvoked(player, self.name, "offensive")
      room:broadcastPlaySound("./packages/standard_cards/audio/card/axe")
      room:setEmotion(player, "./packages/standard_cards/image/anim/axe")
      room:throwCard(self.cost_data, "axe", player, player)
      return true
    elseif event == fk.PreCardEffect then
      room:notifySkillInvoked(player, self.name, "defensive")
      room:broadcastPlaySound("./packages/maneuvering/audio/card/vine")
      room:setEmotion(player, "./packages/maneuvering/image/anim/vine")
      return true
    elseif event == fk.DamageInflicted then
      room:notifySkillInvoked(player, self.name, "negative")
      room:broadcastPlaySound("./packages/maneuvering/audio/card/vineburn")
      room:setEmotion(player, "./packages/maneuvering/image/anim/vineburn")
      data.damage = data.damage + 1
    end
  end,
}
local sk__hanyong_attackrange = fk.CreateAttackRangeSkill{
  name = "#sk__hanyong_attackrange",
  fixed_func = function (self, from)
    if from:hasSkill("sk__hanyong") and from:getEquipment(Card.SubtypeWeapon) == nil and
      #from:getAvailableEquipSlots(Card.SubtypeWeapon) > 0 then
      return 3
    end
  end,
}
sk__hanyong:addRelatedSkill(sk__hanyong_attackrange)
wutugu:addSkill(sk__hanyong)
Fk:loadTranslationTable{
  ["sk__wutugu"] = "兀突骨",
  ["#sk__wutugu"] = "乌戈国主",

  ["sk__hanyong"] = "悍勇",
  [":sk__hanyong"] = "锁定技，若你的装备区里没有武器牌/防具牌，你视为装备着【贯石斧】/【藤甲】。",
}

local caoying = General(extension, "sk__caoying", "wei", 4, 4, General.Female)
local sk__lingruo = fk.CreateTriggerSkill{
  name = "sk__lingruo",
  anim_type = "control",
  events = {fk.TargetSpecified, fk.TargetConfirmed},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) and
      (data.card.trueName == "slash" or data.card:isCommonTrick()) then
      if event == fk.TargetSpecified then
        return #AimGroup:getAllTargets(data.tos) == 1 and data.to ~= player.id
      else
        return data.from ~= player.id
      end
    end
  end,
  on_cost = function (self, event, target, player, data)
    local dat = data.to
    if event == fk.TargetConfirmed then
      dat = data.from
    end
    if player.room:askForSkillInvoke(player, self.name, nil, "#sk__lingruo-invoke::"..dat) then
      self.cost_data = {tos = {dat}}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data.tos[1])
    room:doIndicate(player.id, {to.id})
    local info1, info2 = {}, {}
    for _, id in ipairs(player:getCardIds("he")) do
      local type = Fk:getCardById(id):getTypeString()
      info1[type] = (info1[type] or 0) + 1
    end
    for _, id in ipairs(to:getCardIds("he")) do
      local type = Fk:getCardById(id):getTypeString()
      info2[type] = (info2[type] or 0) + 1
    end
    local n = 0
    for _, type in ipairs({"basic", "trick", "equip"}) do
      info1[type] = info1[type] or 0
      info2[type] = info2[type] or 0
      if info1[type] > info2[type] then
        n = n + 1
      end
    end
    if n == 0 then return end
    for i = 1, n, 1 do
      local choices = {}
      if not player.dead then
        table.insert(choices, 1)
      end
      if not player.dead and not to.dead and not to:isNude() then
        table.insert(choices, 2)
      end
      if not to.dead and not to:isNude() then
        table.insert(choices, 3)
      end
      if #choices == 0 then return end
      local num = table.random(choices)
      if num == 1 then
        player:drawCards(1, self.name)
      else
        local card = table.random(to:getCardIds("he"))
        if num == 2 then
          room:moveCardTo(card, Card.PlayerHand, player, fk.ReasonPrey, self.name, nil, false, player.id)
        else
          room:throwCard(card, self.name, to, to)
        end
      end
    end
  end,
}
local sk__fujian = fk.CreateTriggerSkill{
  name = "sk__fujian",
  anim_type = "control",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Start and
      table.find(player.room:getOtherPlayers(player), function(p)
        return not p:isKongcheng()
      end)
  end,
  on_cost = function(self, event, target, player, data)
    local targets = table.map(table.filter(player.room:getOtherPlayers(player), function(p)
      return not p:isKongcheng()
    end), Util.IdMapper)
    local to = player.room:askForChoosePlayers(player, targets, 1, 1, "#sk__fujian-choose", self.name, true)
    if #to > 0 then
      self.cost_data = {tos = to}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data.tos[1])
    local card = U.askforChooseCardsAndChoice(player, to:getCardIds("h"), {"OK"}, self.name, "#sk__fujian-mark::"..to.id)
    room:setCardMark(Fk:getCardById(card[1]), "@sk__fujian", "0")
    room:setCardMark(Fk:getCardById(card[1]), "sk__fujian_info", {player.id, to.id, 0})
  end,

  refresh_events = {fk.CardUsing, fk.EventLoseSkill, fk.Deathed},
  can_refresh = function (self, event, target, player, data)
    if target == player then
      if event == fk.CardUsing then
        return table.find(player:getCardIds("h"), function(id)
          return Fk:getCardById(id):getMark("sk__fujian_info") ~= 0
        end)
      elseif event == fk.EventLoseSkill then
        return data == self
      else
        return player:hasSkill(self, true, true)
      end
    end
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    if event == fk.CardUsing then
      for _, id in ipairs(player:getCardIds("h")) do
        local card = Fk:getCardById(id)
        if card:getMark("sk__fujian_info") ~= 0 then
          if card:getMark("@sk__fujian") == "0" then
            room:setCardMark(card, "@sk__fujian", 1)
          else
            room:addCardMark(card, "@sk__fujian", 1)
          end
          local mark = card:getMark("sk__fujian_info")
          mark[3] = mark[3] + 1
          room:setCardMark(card, "sk__fujian_info", mark)
        end
      end
    else
      for _, id in ipairs(Fk:getAllCardIds()) do
        local card = Fk:getCardById(id)
        local mark = card:getMark("sk__fujian_info")
        if mark ~= 0 and mark[1] == player.id then
          room:setCardMark(card, "@sk__fujian", 0)
          room:setCardMark(card, "sk__fujian_info", 0)
        end
      end
    end
  end,
}
local sk__fujian_trigger = fk.CreateTriggerSkill{
  name = "#sk__fujian_trigger",
  mute = true,
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    for _, move in ipairs(data) do
      if move.from == player.id then
        for _, info in ipairs(move.moveInfo) do
          if info.fromArea == Card.PlayerHand and Fk:getCardById(info.cardId):getMark("sk__fujian_info") ~= 0 then
            return true
          end
        end
      end
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    for _, move in ipairs(data) do
      if move.from == player.id then
        for _, info in ipairs(move.moveInfo) do
          if info.fromArea == Card.PlayerHand and Fk:getCardById(info.cardId):getMark("sk__fujian_info") ~= 0 then
            local card = Fk:getCardById(info.cardId)
            local mark = card:getMark("sk__fujian_info")
            room:setCardMark(card, "@sk__fujian", 0)
            local src = room:getPlayerById(mark[1])
            if not src.dead and src:hasSkill(sk__fujian) then
              room:doIndicate(mark[1], {mark[2]})
              src:broadcastSkillInvoke("sk__fujian")
              room:notifySkillInvoked(src, "sk__fujian", "offensive")
              if not player.dead then
                room:loseHp(player, 1, "sk__fujian")
              end
              if not src.dead and mark[3] > 0 then
                src:drawCards(mark[3], "sk__fujian")
              end
            end
            room:setCardMark(card, "sk__fujian_info", 0)
          end
        end
      end
    end
  end,
}
sk__fujian:addRelatedSkill(sk__fujian_trigger)
caoying:addSkill(sk__lingruo)
caoying:addSkill(sk__fujian)
Fk:loadTranslationTable{
  ["sk__caoying"] = "曹婴",
  ["#sk__caoying"] = "龙城凤鸣",

  ["sk__lingruo"] = "凌弱",
  [":sk__lingruo"] = "当你使用【杀】或普通锦囊牌指定一名其他角色为唯一目标后，或成为其他角色使用【杀】或普通锦囊牌的目标后，你可以随机X次执行"..
  "以下效果之一：摸一张牌；随机获得其一张牌；令其随机弃置一张牌（X为你的基本牌/锦囊牌/装备牌中数量多于该角色的类别数）。",
  ["sk__fujian"] = "伏间",
  [":sk__fujian"] = "准备阶段，你可以观看一名其他角色的手牌并标记其中一张牌（重复标记会覆盖之前的标记）。若如此做，当该角色失去此牌后，"..
  "你令其失去1点体力，然后你摸X张牌（X为从你标记此牌到其失去此牌期间其使用的牌数）。",
  ["#sk__lingruo-invoke"] = "凌弱：是否对 %dest 执行随机效果？",
  ["#sk__fujian-choose"] = "伏间：观看一名角色的手牌，并标记其中一张牌",
  ["#sk__fujian-mark"] = "伏间：标记 %dest 的一张手牌",
  ["@sk__fujian"] = "伏间",
}

return extension
